package org.yylnb.openplatform.websocket.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.yylnb.openplatform.websocket.handler.MyTextWebSocketHandler;
import org.yylnb.openplatform.websocket.handler.MyWebSocketIntercepter;

/**
 * @author RainLin
 * @date 2020/7/28 - 21:05
 */

@Configuration
public class WebSocketConfig implements WebSocketConfigurer {

    private final MyTextWebSocketHandler myTextWebSocketHandler;


    private final MyWebSocketIntercepter myWebSocketIntercepter;

    public WebSocketConfig(MyTextWebSocketHandler myTextWebSocketHandler, MyWebSocketIntercepter myWebSocketIntercepter) {
        this.myTextWebSocketHandler = myTextWebSocketHandler;
        this.myWebSocketIntercepter = myWebSocketIntercepter;
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(myTextWebSocketHandler,"/websocket/*").setAllowedOrigins("*").addInterceptors(myWebSocketIntercepter);
    }
}
